﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:params="clr-namespace:Elysium.Parameters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource HighlightBrush}"/>
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.DefaultThickness), Mode=OneWay}"/>        
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPaddingValue), Mode=OneWay}"/>
        <!-- Temporary removed to fix bugs 1144, 1174, 1216 -->
        <!--<Setter Property="OverridesDefaultStyle" Value="True"/>-->
        <Setter Property="SnapsToDevicePixels" Value="True"/>        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Separator}">
                    <Border Background="{TemplateBinding Background}"
                            BorderThickness="0"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Line Stroke="{TemplateBinding BorderBrush}"
                              StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessToDoubleConverter}}"
                              X1="0" Y1="0"
                              X2="1" Y2="0"
                              Stretch="Fill"
                              Margin="{TemplateBinding Padding}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="LayoutRoot"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid x:Name="ContentHost"
                  TextBlock.Foreground="{TemplateBinding Foreground}"
                  TextBlock.FontFamily="{TemplateBinding FontFamily}"
                  TextBlock.FontSize="{TemplateBinding FontSize}"
                  TextBlock.FontStretch="{TemplateBinding FontStretch}"
                  TextBlock.FontStyle="{TemplateBinding FontStyle}"
                  TextBlock.FontWeight="{TemplateBinding FontWeight}"
                  TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                  TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                  RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}">
                <ContentPresenter x:Name="HeaderHost"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  Margin="{TemplateBinding Padding}"
                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                <Popup x:Name="PART_Popup"
                       Grid.IsSharedSizeScope="True"
                       AllowsTransparency="True"
                       Focusable="False"
                       IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSubmenuOpen, Mode=TwoWay}"
                       Placement="Custom"
                       PlacementTarget="{Binding ElementName=LayoutRoot}"
                       CustomPopupPlacementCallback="{x:Static params:DropDown.PopupPlacementCallback}">
                    <Border x:Name="PopupRoot"
                            Tag="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"
                            SnapsToDevicePixels="True">
                        <Grid>
                            <Border Background="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBackground)}"
                                    BorderBrush="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderBrush)}"
                                    BorderThickness="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness)}"
                                    TextBlock.Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Foreground}"
                                    TextBlock.FontFamily="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontFamily}"
                                    TextBlock.FontSize="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontSize}"
                                    TextBlock.FontStretch="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStretch}"
                                    TextBlock.FontStyle="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStyle}"
                                    TextBlock.FontWeight="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontWeight}"
                                    TextOptions.TextFormattingMode="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextFormattingMode)}"
                                    TextOptions.TextRenderingMode="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextRenderingMode)}"
                                    RenderOptions.ClearTypeHint="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(RenderOptions.ClearTypeHint)}"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch">
                                <StackPanel IsItemsHost="True"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"/>
                            </Border>
                            <Rectangle x:Name="PopupMask"
                                       Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBackground)}"
                                       Margin="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness), Converter={StaticResource ThicknessConverter}, ConverterParameter='Left'}"
                                       HorizontalAlignment="Left"
                                       VerticalAlignment="Top"
                                       Width="{Binding ElementName=ContentHost, Path=ActualWidth}"/>
                        </Grid>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSubmenuOpen" Value="True">
                <Setter TargetName="PART_Popup" Property="params:DropDown.IsOpen" Value="True"/>                
            </Trigger>
            <Trigger SourceName="PART_Popup" Property="IsOpen" Value="True">
                <Setter TargetName="LayoutRoot" Property="Background" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBackground)}"/>
                <Setter TargetName="LayoutRoot" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderBrush)}"/>
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition SourceName="PART_Popup" Property="IsOpen" Value="True"/>
                    <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultHorizontalPosition" Value="True"/>
                    <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultVerticalPosition" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="LayoutRoot" Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness), Converter={StaticResource ThicknessConverter}, ConverterParameter='Left, Top, Right'}"/>
                    <Setter TargetName="PopupMask" Property="Height" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness), Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter='Top'}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition SourceName="PART_Popup" Property="IsOpen" Value="True"/>
                    <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultHorizontalPosition" Value="True"/>
                    <Condition SourceName="PART_Popup" Property="params:DropDown.IsDefaultVerticalPosition" Value="False"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter TargetName="LayoutRoot" Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness), Converter={StaticResource ThicknessConverter}, ConverterParameter='Left, Right, Bottom'}"/>
                    <Setter TargetName="PopupMask" Property="Height" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness), Converter={StaticResource ThicknessToDoubleConverter}, ConverterParameter='Bottom'}"/>
                    <Setter TargetName="PopupMask" Property="VerticalAlignment" Value="Bottom"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding ElementName=PopupRoot, Path=Tag}" Value="True"/>
                    <Condition Binding="{Binding ElementName=PART_Popup, Path=(params:DropDown.IsDefaultVerticalPosition)}" Value="True"/>
                </MultiDataTrigger.Conditions>
                <MultiDataTrigger.Setters>
                    <Setter TargetName="PopupRoot" Property="Effect">
                        <Setter.Value>
                            <DropShadowEffect Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}"
                                                          BlurRadius="4" ShadowDepth="2"
                                                          Direction="315"
                                                          Opacity="0.3"/>
                        </Setter.Value>
                    </Setter>
                    <Setter TargetName="PopupRoot" Property="Background" Value="{StaticResource TransparentBrush}"/>
                    <Setter TargetName="PopupRoot" Property="Padding" Value="0,0,6,6"/>
                </MultiDataTrigger.Setters>
            </MultiDataTrigger>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding ElementName=PopupRoot, Path=Tag}" Value="True"/>
                    <Condition Binding="{Binding ElementName=PART_Popup, Path=(params:DropDown.IsDefaultVerticalPosition)}" Value="False"/>
                </MultiDataTrigger.Conditions>
                <MultiDataTrigger.Setters>
                    <Setter TargetName="PopupRoot" Property="Effect">
                        <Setter.Value>
                            <DropShadowEffect Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}"
                                                          BlurRadius="4" ShadowDepth="0"
                                                          Direction="45"
                                                          Opacity="0.3"/>
                        </Setter.Value>
                    </Setter>
                    <Setter TargetName="PopupRoot" Property="Background" Value="{StaticResource TransparentBrush}"/>
                    <Setter TargetName="PopupRoot" Property="Padding" Value="0,4,4,0"/>
                </MultiDataTrigger.Setters>
            </MultiDataTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="LayoutRoot"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                TextBlock.Foreground="{TemplateBinding Foreground}"
                TextBlock.FontFamily="{TemplateBinding FontFamily}"
                TextBlock.FontSize="{TemplateBinding FontSize}"
                TextBlock.FontStretch="{TemplateBinding FontStretch}"
                TextBlock.FontStyle="{TemplateBinding FontStyle}"
                TextBlock.FontWeight="{TemplateBinding FontWeight}"
                TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <ContentPresenter x:Name="HeaderHost"
                                ContentSource="Header"
                                RecognizesAccessKey="True"
                                Margin="{TemplateBinding Padding}"/>
        </Border>
    </ControlTemplate>

    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="LayoutRoot"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid TextBlock.Foreground="{TemplateBinding Foreground}"
                  TextBlock.FontFamily="{TemplateBinding FontFamily}"
                  TextBlock.FontSize="{TemplateBinding FontSize}"
                  TextBlock.FontStretch="{TemplateBinding FontStretch}"
                  TextBlock.FontStyle="{TemplateBinding FontStyle}"
                  TextBlock.FontWeight="{TemplateBinding FontWeight}"
                  TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                  TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                  RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                  Margin="{TemplateBinding Padding}"
                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="ContextMenuIconSizeGroup"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="IconHost"
                                  Grid.Column="0"
                                  ContentSource="Icon"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"
                                  MinWidth="16" MinHeight="16"/>
                <ContentPresenter x:Name="HeaderHost"
                                  Grid.Column="1"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:General.BoldPaddingValue), Mode=OneWay, Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter='Left, Right'}"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"/>
                <Polygon x:Name="ArrowGlyph"
                         Grid.Column="2"
                         Fill="{StaticResource MiddleLightBrush}"
                         StrokeThickness="0"
                         Stretch="Uniform"
                         Margin="{TemplateBinding params:MenuItem.ArrowMargin}"
                         HorizontalAlignment="Right" VerticalAlignment="Center"
                         Width="{TemplateBinding params:MenuItem.ArrowSize}"
                         Height="{TemplateBinding params:MenuItem.ArrowSize}">
                    <Polygon.Points>
                        <PointCollection>
                            <Point X="0" Y="0"/>
                            <Point X="2" Y="2"/>
                            <Point X="0" Y="4"/>
                        </PointCollection>
                    </Polygon.Points>
                </Polygon>
                <Popup x:Name="PART_Popup"
                       Grid.Column="0" Grid.IsSharedSizeScope="True"
                       AllowsTransparency="True"
                       Focusable="False"
                       Placement="Right"
                       PlacementTarget="{Binding ElementName=LayoutRoot}"
                       IsOpen="{TemplateBinding IsSubmenuOpen}"
                       PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                       Tag="{DynamicResource {x:Static SystemParameters.MenuAnimationKey}}">
                    <Border x:Name="PopupRoot"
                            Tag="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
                        <Border Background="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBackground)}"
                                BorderBrush="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderBrush)}"
                                BorderThickness="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness)}"
                                TextBlock.Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Foreground}"
                                TextBlock.FontFamily="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontFamily}"
                                TextBlock.FontSize="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontSize}"
                                TextBlock.FontStretch="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStretch}"
                                TextBlock.FontStyle="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStyle}"
                                TextBlock.FontWeight="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontWeight}"
                                TextOptions.TextFormattingMode="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextFormattingMode)}"
                                TextOptions.TextRenderingMode="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextRenderingMode)}"
                                RenderOptions.ClearTypeHint="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(RenderOptions.ClearTypeHint)}"
                                SnapsToDevicePixels="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=SnapsToDevicePixels}">
                            <StackPanel IsItemsHost="True"
                                        KeyboardNavigation.DirectionalNavigation="Cycle"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch"/>
                        </Border>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="IconHost" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsSubmenuOpen" Value="True">
                <Setter TargetName="ArrowGlyph" Property="Fill" Value="{StaticResource AccentBrush}"/>
            </Trigger>
            <Trigger Property="IsSuspendingPopupAnimation" Value="True">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>
            <Trigger SourceName="PART_Popup" Property="Tag" Value="False">
                <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None"/>
            </Trigger>
            <DataTrigger Binding="{Binding ElementName=PopupRoot, Path=Tag}" Value="True">
                <Setter TargetName="PopupRoot" Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}"
                                          BlurRadius="4" ShadowDepth="2"
                                          Direction="315"
                                          Opacity="0.3"/>
                    </Setter.Value>
                </Setter>
                <Setter TargetName="PopupRoot" Property="Background" Value="{StaticResource TransparentBrush}"/>
                <Setter TargetName="PopupRoot" Property="Padding" Value="0,0,6,6"/>
            </DataTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid TextBlock.Foreground="{TemplateBinding Foreground}"
                  TextBlock.FontFamily="{TemplateBinding FontFamily}"
                  TextBlock.FontSize="{TemplateBinding FontSize}"
                  TextBlock.FontStretch="{TemplateBinding FontStretch}"
                  TextBlock.FontStyle="{TemplateBinding FontStyle}"
                  TextBlock.FontWeight="{TemplateBinding FontWeight}"
                  TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                  TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                  RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                  Margin="{TemplateBinding Padding}"
                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="ContextMenuIconSizeGroup"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="ContextMenuShortcutSizeGroup"/>
                </Grid.ColumnDefinitions>
                <Path x:Name="CheckBullet"
                      Grid.Column="0"
                      Stroke="{StaticResource LowlightBrush}"
                      StrokeThickness="{TemplateBinding params:General.BoldThicknessValue}"
                      Stretch="Uniform"
                      Visibility="Collapsed"
                      HorizontalAlignment="Center" VerticalAlignment="Center"
                      Width="{TemplateBinding params:MenuItem.BulletSize}" Height="{TemplateBinding params:MenuItem.BulletSize}">
                    <Path.Data>
                        <GeometryGroup>
                            <LineGeometry StartPoint="0,3" EndPoint="4,8"/>
                            <LineGeometry StartPoint="4,8" EndPoint="8,0"/>
                        </GeometryGroup>
                    </Path.Data>
                </Path>
                <ContentPresenter x:Name="IconHost"
                                  Grid.Column="0"
                                  ContentSource="Icon"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"
                                  MinWidth="16" MinHeight="16"/>
                <ContentPresenter x:Name="HeaderHost"
                                  Grid.Column="1"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:General.BoldPaddingValue), Mode=OneWay, Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter='Left, Right'}"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"/>
                <TextBlock Grid.Column="2"
                           Text="{TemplateBinding InputGestureText}"
                           Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:General.BoldPaddingValue), Mode=OneWay, Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter='Left, Right'}"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"/>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="IconHost" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsCheckable" Value="True">
                <Setter TargetName="IconHost" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="CheckBullet" Property="Visibility" Value="Visible"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type MenuItem}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Foreground, Mode=OneWay}"/>
        <Setter Property="FontFamily" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontFamily, Mode=OneWay}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontSize, Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStretch, Mode=OneWay}"/>
        <Setter Property="FontStyle" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontStyle, Mode=OneWay}"/>
        <Setter Property="FontWeight" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontWeight, Mode=OneWay}"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextFormattingMode), Mode=OneWay}"/>
        <Setter Property="TextOptions.TextRenderingMode" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(TextOptions.TextRenderingMode), Mode=OneWay}"/>
        <Setter Property="RenderOptions.ClearTypeHint" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(RenderOptions.ClearTypeHint), Mode=OneWay}"/>
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
        <Setter Property="HorizontalContentAlignment" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=HorizontalContentAlignment}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=VerticalContentAlignment}"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Padding, Mode=OneWay}"/>
        <!-- Temporary removed to fix bugs 1144, 1174, 1216 -->
        <!--<Setter Property="OverridesDefaultStyle" Value="True"/>-->
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Style.Triggers>            
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}"/>
                <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness), Converter={StaticResource ThicknessConverter}, ConverterParameter='Left, Top, Right'}"/>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelItemTemplateKey}}"/>
                <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=(params:MenuBase.SubmenuBorderThickness), Converter={StaticResource ThicknessConverter}, ConverterParameter='Left, Top, Right'}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{StaticResource HighlightBrush}"/>
                <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Role" Value="TopLevelHeader"/>
                    <Condition Property="IsHighlighted" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter Property="Background" Value="{StaticResource HighlightBrush}"/>
                    <Setter Property="BorderBrush" Value="{StaticResource HighlightBrush}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Role" Value="TopLevelItem"/>
                    <Condition Property="IsHighlighted" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter Property="Background" Value="{StaticResource HighlightBrush}"/>
                    <Setter Property="BorderBrush" Value="{StaticResource HighlightBrush}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}"/>
            </Trigger>            
        </Style.Triggers>        
    </Style>
    
</ResourceDictionary>